package com.wyc.alipay.config;

import com.alipay.easysdk.factory.Factory;
import com.alipay.easysdk.kernel.Config;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;

@Slf4j
@ConfigurationProperties(prefix = "alipay")
@Component
@Data
public class AlipayConfig {

    private String appId;
    /** 应用私钥 */
    private String merchantPrivateKey;
    /** 支付宝公钥 */
    private String publicKey;
    /** 回调地址(使用了内网穿透) */
    private String notifyUrl;

    @PostConstruct
    public void init(){
        Config config = new Config();
        // 基础配置
        config.protocol = "https";
        config.gatewayHost = "openapi.alipaydev.com";
        config.signType = "RSA2";

        // 业务配置
        config.appId = this.appId;
        config.alipayPublicKey = this.publicKey;
        config.merchantPrivateKey = this.merchantPrivateKey;
        config.notifyUrl = this.notifyUrl;

        Factory.setOptions(config);
        log.info("支付宝配置初始化完成...");
    }

}
